package com.github.kongchen.swagger.docgen.mavenplugin;

import java.util.Iterator;
import java.util.Set;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.springframework.stereotype.Controller;

import com.github.kongchen.swagger.docgen.AbstractDocumentSource;
import com.github.kongchen.swagger.docgen.GenerateException;
import com.github.kongchen.swagger.docgen.LogAdapter;
import com.github.kongchen.swagger.docgen.reader.AbstractReader;
import com.github.kongchen.swagger.docgen.reader.PSApiReader;

import io.swagger.annotations.Api;

public class PSMavenDocumentSource extends AbstractDocumentSource{
	 public PSMavenDocumentSource(ApiSource apiSource, Log log) throws MojoFailureException {
	        super(new LogAdapter(log), apiSource);
	    }

	@Override
	public void doLoadDocuments() throws GenerateException 
	{
		Set<Class<?>> clazzs=apiSource.getValidClasses(Api.class);
		//排除@Controller注解
		Iterator<Class<?>> it=clazzs.iterator();
		Class<?> clazz;
		while(it.hasNext())
		{
			clazz=it.next();
			if(clazz.getAnnotation(Controller.class)!=null)
				it.remove();
		}
		swagger = resolveApiReader().read(clazzs);
	}
	
	protected AbstractReader getDefaultReader()
    {
    	return  new PSApiReader(swagger, LOG);
    }
}
